import java.util.Scanner;

/**
 * @author gao
 * @date 2025/6/8 10:34
 */

public class Solution {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;

        // 创建一个二维数组dp，用于存储到达每个位置的路径数
        int[][] dp = new int[m + 1][n + 1];
        // 初始化dp[1][0]为1，表示从起点到第一列的路径数
        dp[1][0] = 1;

        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                // 如果当前位置没有障碍物，则路径数等于上方和左方位置的路径数之和
                if (obstacleGrid[i - 1][j - 1] == 0) {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                }
            }
        }
        // 返回到达终点的路径数
        return dp[m][n];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int m = in.nextInt();
            int n = in.nextInt();
            int[][] ob = new int[m][n];

            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    ob[i][j] = in.nextInt();
                }
            }

            Solution solution = new Solution();
            System.out.println(solution.uniquePathsWithObstacles(ob));
        }
    }
}